#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

static void sig_handler(int sig){
    printf("执行信号处理函数...\n");
}

int main()
{
    struct sigaction sig = {0};
    sigset_t sig_set;

    sig.sa_handler = sig_handler;
    sig.sa_flags = 0;

    if(-1 == sigaction(SIGINT, &sig, NULL))
        exit(-1);

    sigemptyset(&sig_set);
    sigaddset(&sig_set, SIGINT);

    if(-1 == sigprocmask(SIG_BLOCK, &sig_set, NULL))
        exit(-1);

    raise(SIGINT);

    sleep(2);
    printf("sleep end\n");

    if(-1 == sigprocmask(SIG_UNBLOCK, &sig_set, NULL))
        exit(-1);

    exit(0);
}